package com.xunshibao.acquiredata;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

public class PConvert {
    private Map<String, String> map = new HashMap<String, String>(34);

    public PConvert() {
        map.put("1", "1100 ");
        map.put("2", "3100 ");
        map.put("3", "2300 ");
        map.put("4", "2200 ");
        map.put("5", "2100 ");
        map.put("6", "1200 ");
        map.put("7", "3400 ");
        map.put("8", "3200 ");
        map.put("9", "3300 ");
        map.put("10", "6100");
        map.put("11", "4200");
        map.put("12", "4400");
        map.put("13", "4300");
        map.put("14", "6200");
        map.put("15", "5100");
        map.put("16", "3700");
        map.put("17", "3500");
        map.put("18", "4100");
        map.put("19", "5000");
        map.put("20", "5300");
        map.put("21", "1300");
        map.put("22", "3600");
        map.put("23", "1400");
        map.put("24", "5200");
        map.put("25", "4500");
        map.put("26", "1500");
        map.put("27", "6400");
        map.put("28", "6300");
        map.put("29", "6500");
        map.put("30", "4600");
        map.put("31", "5400");
        map.put("32", "8100");
        map.put("33", "8200");
        map.put("34", "7100");
    }

    public String convertCode(String code) {
        return map.get(code);
    }

    @Test
    public void doConvert() {
        File univFile = new File("univ.txt");
        File univFile2 = new File("unived.txt");
        BufferedWriter bufWriter = null;
        BufferedReader bufReader = null;
        try {
            bufWriter = new BufferedWriter(new FileWriter(univFile2));
            bufReader = new BufferedReader(new FileReader(univFile));
            String line;
            String[] words;
            while ((line = bufReader.readLine()) != null) {
                words = line.split("\t");
                bufWriter.append(convertCode(words[0]));
                bufWriter.append('\t');
                bufWriter.append(words[1]);
                bufWriter.append('\t');
                bufWriter.append(words[2]);
                bufWriter.append('\n');
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bufWriter.close();
                bufReader.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}
